<?php
/*
 * ebiz front
 *
 * FeatureController
 *
 * @author allen
 *
 */
require_once '../app/core/controllers/BaseController.php';
require_once '../app/views/FeatureView.php';
require_once '../app/services/FeatureService.php';
require_once '../app/core/utils/HttpUtil.class.php';
require_once '../app/services/SpecialProductItemService.php';
require_once '../app/models/ProductItemDao.php';

class FeatureController extends BaseController {
	
    public function index($param = array()){
    	$arr_features = array(
    	   'newversion',
    	   'christmas',
    	   'newyear',
    	   'autumn',
    	   'digital',
    	   'love',
    	   'newyear2010'
    	);
    	if(in_array($param['featurePage'], $arr_features)){
    	   self::$param['featurePage']();
    	   exit;
    	}
    	HttpUtil::renderError();
    }

    public function newversion(){
        $specialProductItemService = new  SpecialProductItemService();
        $arr_mproducts = array();
        $arr_types = array(48,49,50,51,52,53);//促销商品类型 化妆品、服装、鞋类、笔记本、手机、数码产品
        foreach ($arr_types as $int_key => $int_type){
            $arr_sproducts = $specialProductItemService->getProductItemsByType($int_type);
            foreach ( $arr_sproducts as $int_skey => $arr_product ){
                $arr_sproducts[$int_skey]['url_title'] = urlencode($arr_product['url_title']);
                $arr_sproducts[$int_skey]['description'] = $arr_product['title'];
                $arr_sproducts[$int_skey]['p_image'] = empty($arr_product['iname'])? ConfigConstants::getDefaultProductImagePath(160) : ConfigConstants::getProductImagePath($arr_product['ifolder'],$arr_product['iname'], 160);
            }
            $arr_mproducts[$int_key] = $arr_sproducts;
        }
    	require_once '../app/views/feature/newversionView.php';
    }

    public function autumn(){
        $specialProductItemService = new  SpecialProductItemService();
        $arr_products = $specialProductItemService->getProductItemsByType(47);//秋装
        if(!empty($arr_products)){
	        foreach ( $arr_products as $int_skey => $arr_product ){
	            $arr_products[$int_skey]['url_title'] = urlencode($arr_product['url_title']);
	            $arr_products[$int_skey]['description'] = $arr_product['title'];
	            $arr_products[$int_skey]['p_image'] = empty($arr_product['iname'])? ConfigConstants::getDefaultProductImagePath(160) : ConfigConstants::getProductImagePath($arr_product['ifolder'],$arr_product['iname'], 160);
	        }
        }else{
        	$arr_products = array();
        }

        require_once '../app/views/feature/autumnView.php';
    }

    //圣诞节专场
    public function christmas(){
       $specialProductItemService = new  SpecialProductItemService();
        $arr_products = $specialProductItemService->getProductItemsByType(60); 
        if(!empty($arr_products)){
	        foreach ( $arr_products as $int_skey => $arr_product ){
	            $arr_products[$int_skey]['url_title'] = urlencode($arr_product['url_title']);
	            $arr_products[$int_skey]['description'] = $arr_product['title'];
	            $arr_products[$int_skey]['p_image'] = empty($arr_product['iname'])? ConfigConstants::getDefaultProductImagePath(160) : ConfigConstants::getProductImagePath($arr_product['ifolder'],$arr_product['iname'], 160);
	        }
        }else{
        	$arr_products = array();
        }

        $items_id_ads = $specialProductItemService->getProductItemsByType(63);
        if (!empty($items_in_ads))
        {
        	foreach ($items_in_ads as $int_skey => $item_in_ads)
        	{
        		$items_id_ads[$int_skey]['url_title'] = urlencode($item_in_ads['url_title']);
        	}
        }
        else
        {
        	$items_in_ads = array();
        }
        
        require_once '../app/views/feature/christmasView.php';        
    	
    } 

    //元旦专场
    public function newyear(){
       $specialProductItemService = new  SpecialProductItemService();
       
        $arr_products = $specialProductItemService->getProductItemsByType(61); 
        if(!empty($arr_products)){
	        foreach ( $arr_products as $int_skey => $arr_product ){
	            $arr_products[$int_skey]['url_title'] = urlencode($arr_product['url_title']);
	            $arr_products[$int_skey]['description'] = $arr_product['title'];
	            $arr_products[$int_skey]['p_image'] = empty($arr_product['iname'])? ConfigConstants::getDefaultProductImagePath(160) : ConfigConstants::getProductImagePath($arr_product['ifolder'],$arr_product['iname'], 160);
	        }
        }else{
        	$arr_products = array();
        }

        
        $arr_products1 = $specialProductItemService->getProductItemsByType(62); 
        if(!empty($arr_products1)){
	        foreach ( $arr_products1 as $int_skey1 => $arr_product1 ){
	            $arr_products1[$int_skey1]['url_title'] = urlencode($arr_product1['url_title']);
	            $arr_products1[$int_skey1]['description'] = $arr_product1['title'];
	            $arr_products1[$int_skey1]['p_image'] = empty($arr_product1['iname'])? ConfigConstants::getDefaultProductImagePath(160) : ConfigConstants::getProductImagePath($arr_product1['ifolder'],$arr_product1['iname'], 160);
	        }
        }else{
        	$arr_products1 = array();
        }
                
        require_once '../app/views/feature/newyearView.php';        
    	
    } 

        //数码专场
    public function digital(){
        $specialProductItemService = new  SpecialProductItemService();
        /*$arr_products = $specialProductItemService->getProductItemsByType(63); 
        if(!empty($arr_products)){
	        foreach ( $arr_products as $int_skey => $arr_product )
	        {
	            $arr_products[$int_skey]['url_title'] = urlencode($arr_product['url_title']);
	        }
        }else{
        	$arr_products = array();
        }*/
        $items_id_ads = $specialProductItemService->getProductItemsByType(64);
        if (!empty($items_in_ads))
        {
        	foreach ($items_in_ads as $int_skey => $item_in_ads)
        	{
        		$items_id_ads[$int_skey]['url_title'] = urlencode($item_in_ads['url_title']);
        	}
        }
        else
        {
        	$items_in_ads = array();
        }   

        require_once '../app/views/feature/digitalView.php';        
    	
    } 

    //情人节专场
    public function love(){
       $specialProductItemService = new  SpecialProductItemService();      
        $items_id_ads = $specialProductItemService->getProductItemsByType(65);
        if (!empty($items_in_ads))
        {
        	foreach ($items_in_ads as $int_skey => $item_in_ads)
        	{
        		$items_id_ads[$int_skey]['url_title'] = urlencode($item_in_ads['url_title']);
        	}
        }
        else
        {
        	$items_in_ads = array();
        }
       
        $arr_products1 = $specialProductItemService->getProductItemsByType(66); 
        if(!empty($arr_products1)){
	        foreach ( $arr_products1 as $int_skey1 => $arr_product1 ){
	            $arr_products1[$int_skey1]['url_title'] = urlencode($arr_product1['url_title']);
	            $arr_products1[$int_skey1]['description'] = $arr_product1['title'];
	            $arr_products1[$int_skey1]['p_image'] = empty($arr_product1['iname'])? ConfigConstants::getDefaultProductImagePath(200) : ConfigConstants::getProductImagePath($arr_product1['ifolder'],$arr_product1['iname'], 200);
	        }
        }else{
        	$arr_products1 = array();
        }

        $arr_products2 = $specialProductItemService->getProductItemsByType(67); 
        if(!empty($arr_products2)){
	        foreach ( $arr_products2 as $int_skey2 => $arr_product2 ){
	            $arr_products2[$int_skey2]['url_title'] = urlencode($arr_product2['url_title']);
	            $arr_products2[$int_skey2]['description'] = $arr_product2['title'];
	            $arr_products2[$int_skey2]['p_image'] = empty($arr_product2['iname'])? ConfigConstants::getDefaultProductImagePath(200) : ConfigConstants::getProductImagePath($arr_product2['ifolder'],$arr_product2['iname'], 200);
	        }
        }else{
        	$arr_products2 = array();
        }        
        require_once '../app/views/feature/loveView.php';        
    	
    } 
    

    //2010春节专场
    public function newyear2010(){
       $specialProductItemService = new  SpecialProductItemService();      
        $arr_products = $specialProductItemService->getProductItemsByType(70); 
        if(!empty($arr_products)){
	        foreach ( $arr_products as $int_skey => $arr_product ){
	            $arr_products[$int_skey]['url_title'] = urlencode($arr_product['url_title']);
	            $arr_products[$int_skey]['description'] = $arr_product['title'];
	            $arr_products[$int_skey]['p_image'] = empty($arr_product['iname'])? ConfigConstants::getDefaultProductImagePath(160) : ConfigConstants::getProductImagePath($arr_product['ifolder'],$arr_product['iname'], 160);
	        }
        }else{
        	$arr_products = array();
        }
       
        $arr_products1 = $specialProductItemService->getProductItemsByType(68); 
        if(!empty($arr_products1)){
	        foreach ( $arr_products1 as $int_skey1 => $arr_product1 ){
	            $arr_products1[$int_skey1]['url_title'] = urlencode($arr_product1['url_title']);
	            $arr_products1[$int_skey1]['description'] = $arr_product1['title'];
	            $arr_products1[$int_skey1]['p_image'] = empty($arr_product1['iname'])? ConfigConstants::getDefaultProductImagePath(160) : ConfigConstants::getProductImagePath($arr_product1['ifolder'],$arr_product1['iname'], 160);
	        }
        }else{
        	$arr_products1 = array();
        }

        $arr_products2 = $specialProductItemService->getProductItemsByType(69); 
        if(!empty($arr_products2)){
	        foreach ( $arr_products2 as $int_skey2 => $arr_product2 ){
	            $arr_products2[$int_skey2]['url_title'] = urlencode($arr_product2['url_title']);
	            $arr_products2[$int_skey2]['description'] = $arr_product2['title'];
	            $arr_products2[$int_skey2]['p_image'] = empty($arr_product2['iname'])? ConfigConstants::getDefaultProductImagePath(160) : ConfigConstants::getProductImagePath($arr_product2['ifolder'],$arr_product2['iname'], 160);
	        }
        }else{
        	$arr_products2 = array();
        }

        $arr_products3 = $specialProductItemService->getProductItemsByType(71); 
        if(!empty($arr_products3)){
	        foreach ( $arr_products3 as $int_skey3 => $arr_product3 ){
	            $arr_products3[$int_skey3]['url_title'] = urlencode($arr_product3['url_title']);
	            $arr_products3[$int_skey3]['description'] = $arr_product3['title'];
	            $arr_products3[$int_skey3]['p_image'] = empty($arr_product3['iname'])? ConfigConstants::getDefaultProductImagePath(160) : ConfigConstants::getProductImagePath($arr_product3['ifolder'],$arr_product3['iname'], 160);
	        }
        }else{
        	$arr_products3 = array();
        } 
                
        require_once '../app/views/feature/newyear2010View.php';        
    	
    }     
    
}



